<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>商品添加</title>

    <link rel="stylesheet" th:href="@{/css/admin.css}">
    <style>
        .frm{
            width: 500px;
            height: 800px;
            margin-top: 30px;
        }
    </style>

    <script type="text/javascript">
        // 切换图片
        function showImg(){
            // 文件访问对象
            var f = new FileReader();
            f.onload = function (param){
                img.src = param.target.result;
            }
            f.readAsDataURL(file.files[0]);
        }
    </script>
</head>
<body>

<div class="frm">
    <div class="title">
        商品信息添加
    </div>

    <form action="/admin/goods/add_submit" method="post" enctype="multipart/form-data">
        <table>
            <tr>
                <td>商品名称</td>
                <td>
                    <input type="text" name="goodsName" required="required">
                </td>
            </tr>
            <tr>
                <td>价格</td>
                <td>
                    <input type="text" name="price" required="required">
                </td>
            </tr>
            <tr>
                <td>产地</td>
                <td>
                    <input type="text" name="address" required="required">
                </td>
            </tr>
            <tr>
                <td>生产日期</td>
                <td>
                    <input type="date" name="produceDate" required="required">
                </td>
            </tr>
            <tr>
                <td>图片</td>
                <td>
                    <img src="/img/default.jpg" width="80" height="100" id="img">
<!--                    <img th:src="@{/img/default.jpg}" width="80" height="100">-->
                    <br>
                    <input type="file" name="file" onchange="showImg()">
                </td>
            </tr>
            <tr>
                <td>商品分类</td>
                <td>
                    <select name="category.categoryId">
                        <option value="">请选择</option>
                        <option th:each="category:${categoryList}"
                            th:value="${category.categoryId}"
                            th:text="${category.categoryName}">

                        </option>
                    </select>
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <input type="submit" value="添加">
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>